<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <script>
        (function(window, undefined) {
            var jQuery = function(selector) {
                return new jQuery.fn.init(selector);
            }
            jQuery.fn = jQuery.prototype = {
                    constructor: jQuery,
                    init: function(selector) {
                        var elements = document.querySelectorAll(selector);
                        [].push.apply(this, elements);
                    },
                    css: function() {
                        console.log('css is ok');
                    }
                }
                // 把init的原型对象替换成jquery的原型对象
            jQuery.fn.init.prototype = jQuery.fn;
            // 暴露
            window.jQuery = window.$ = jQuery;
        })(window)

        var $divs = $('div');
        console.log($divs);

        // (function(window, undefined) {
        //     var jQuery = function(selector) {
        //         return new jQuery.fn.init(selector);
        //     }
        //     jQuery.fn = jQuery.prototype = {
        //         constructor: jQuery,
        //         init: function(selector) {
        //             var elements = document.querySelectorAll(selector);
        //             [].push.apply(this, elements);
        //         }
        //     }
        //     window.jQuery = window.$ = jQuery;
        // })(window)

        var $divs = $('div');
        console.log($divs);
        $divs.css();
    </script>
</body>

</html>